﻿using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using System.Data.SqlClient;
using System.Data;

namespace DAO
{
   public class DiaDiemDAO
    {
        public static DataTable LayThongTinDiaDiemNhanHang()
        {
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinDiaDiemNhanHang", null);
            return dt;
        }
        public static DataTable LayThongTinKhuVuc()
        {
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinKhuVuc", null);
            return dt;
        }
        public static DataTable LayThongTinVuaNhap(string MaDiaDiem)
        {
            List<SqlParameter> sqlParams = new List<SqlParameter>();
            sqlParams.Add(new SqlParameter("@MaDiaDiem", MaDiaDiem));
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinVuaNhap", sqlParams);
            return dt;
        }
        #region KiemTraNhapĐiaDiem
       
        public static bool NhapDiaDiem(DiaDiemDTO diadiem)
        {
            bool result = false;
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaDiaDiem", diadiem.MaDiaDiem));
                sqlParams.Add(new SqlParameter("@TenDiaDiem", diadiem.TenDiaDiem));
                sqlParams.Add(new SqlParameter("@MaLoaiDiaDiem",diadiem.MaLoaiDiaDiemNhanHang));
                sqlParams.Add(new SqlParameter("@DiaChi", diadiem.DiaChi));
                sqlParams.Add(new SqlParameter("@SoDienThoai", diadiem.SoDienThoai));
                sqlParams.Add(new SqlParameter("@ToaDo", diadiem.ToaDo));
                sqlParams.Add(new SqlParameter("@NguoiLienHe", diadiem.NguoiLienHe));
                sqlParams.Add(new SqlParameter("@Email", diadiem.Email));
                sqlParams.Add(new SqlParameter("@MaKhuVuc", diadiem.MaKhuVuc));
                // Call Store Procedure
                int n = SqlDataAccessHelper.ExecuteNoneQuery("spInsertDiaDiem", sqlParams);
                if (n == 1)
                    result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        public static bool KiemTraNhapDiaDiem(String MaDiaDiem)
        {
            bool result = false;
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaDiaDiem", MaDiaDiem));
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spKiemTraNhapDiaDiem", sqlParams);
                if (dt.Rows.Count >= 1)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        #endregion
    }
}
